﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Text;
using System.Configuration;
using System.Collections.Generic;
using System.Data.SqlClient;
using Project.dalSql;
using System.Web.SessionState;
using WISD.Common;

namespace WISD.CarFriend.Web.Admin.Control
{
    /// <summary>
    /// Summary description for SubstituteDriving
    /// </summary>
    public class SubstituteDriving : IHttpHandler, IReadOnlySessionState    
    {
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            string name = NullHelper.NullProcess<string>(context.Request["Name"], "");
            string vehicleNo = NullHelper.NullProcess<string>(context.Request["VehicleNo"], "");
            string address = NullHelper.NullProcess<string>(context.Request["Address"], "");
            string destination = NullHelper.NullProcess<string>(context.Request["Destination"], "");
            string mileage = NullHelper.NullProcess<string>(context.Request["Mileage"], "-1");
            string mobileTel = NullHelper.NullProcess<string>(context.Request["MobileTel"], "");
            string remarks = NullHelper.NullProcess<string>(context.Request["Remarks"], "");
            string state = NullHelper.NullProcess<string>(context.Request["State"], "-1");
            string reviser = context.Session["UserCode"].ToString();
            string driveId = NullHelper.NullProcess<string>(context.Request["DriveId"], "");
            string reserveDate = NullHelper.NullProcess<string>(context.Request["ReserveDate"], "");
            string arriveDate = NullHelper.NullProcess<string>(context.Request["ArriveDate"], "");
            string employeeId = NullHelper.NullProcess<string>(context.Request["EmployeeId"], "");

            string action = NullHelper.NullProcess<string>(context.Request["Action"], "");
            int pageSize = NullHelper.NullProcess<int>(context.Request["PageSize"], 0);
            int pageIndex = NullHelper.NullProcess<int>(context.Request["CurrentPage"], 0);
            string condition = NullHelper.NullProcess<string>(context.Request["Condition"], "");
            string main = NullHelper.NullProcess<string>(context.Request["Main"], "");

            if (action == "Init")
            {
                context.Response.Write(BLL.OA.SubstituteDrivingModule.GetData(pageSize, pageIndex, condition));
                context.Response.End();
            }

            if (action == "GetOne")
            {
                context.Response.Write(BLL.OA.SubstituteDrivingModule.GetOne(main));
                context.Response.End();
            }

            if (action == "AddEntity")
            {
                Dictionary<string, string> dictionary = new Dictionary<string, string>();
                dictionary.Add("Name", name);
                dictionary.Add("VehicleNo", vehicleNo);
                dictionary.Add("Address", address);
                dictionary.Add("Destination", destination);
                dictionary.Add("Mileage", mileage);
                dictionary.Add("MobileTel", mobileTel);
                dictionary.Add("Remarks", remarks);
                dictionary.Add("State", state);
                dictionary.Add("Reviser", reviser);
                dictionary.Add("ReviseDate", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                dictionary.Add("DriveId", driveId);
                dictionary.Add("ReserveDate", reserveDate);
                dictionary.Add("ArriveDate", arriveDate);
                dictionary.Add("EmployeeId", employeeId);

                if (BLL.OA.SubstituteDrivingModule.AddEntity(dictionary).Equals("Success"))
                {
                    context.Response.Write("Success");
                }
                else
                {
                    context.Response.Write("Failure");
                }
                context.Response.End();
            }

            if (action == "DeleteEntity")
            {
                context.Response.Write(BLL.OA.SubstituteDrivingModule.DeleteEntity(main));
                context.Response.End();
            }

            if (action == "EditEntity")
            {
                Dictionary<string, string> dictionary = new Dictionary<string, string>();
                dictionary.Add("SubstituteDrivingID", main);
                dictionary.Add("Name", name);
                dictionary.Add("VehicleNo", vehicleNo);
                dictionary.Add("Address", address);
                dictionary.Add("Destination", destination);
                dictionary.Add("Mileage", mileage);
                dictionary.Add("MobileTel", mobileTel);
                dictionary.Add("Remarks", remarks);
                dictionary.Add("State", state);
                dictionary.Add("Reviser", reviser);
                dictionary.Add("ReviseDate", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                dictionary.Add("DriveId", driveId);
                dictionary.Add("ReserveDate", reserveDate);
                dictionary.Add("ArriveDate", arriveDate);
                dictionary.Add("EmployeeId", employeeId);

                if (BLL.OA.SubstituteDrivingModule.EditEntity(dictionary).Equals("Success"))
                {
                    context.Response.Write("Success");
                }
                else
                {
                    context.Response.Write("Failure");
                }
                context.Response.End();
            }

            if (action == "GetDriveId")
            {
                context.Response.Write(BLL.OA.SubstituteDrivingModule.GetDriveId());
                context.Response.End();
            }

            if (action == "GetEmployee")
            {
                context.Response.Write(BLL.OA.SubstituteDrivingModule.GetEmployee());
                context.Response.End();
            }

        }


        /// <summary>
        /// IsReusable
        /// </summary>
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}